<template>
  <div class="page">
    <navigation>{{ $t('默认货币') }}</navigation>
    <div class="page-space"></div>
    <div class="list">
      <div v-for="(item, key) in currencies" :key="key" class="item" @click="changeFn(item)">
        <span>{{ $t(item.label) }}</span>
        <i v-if="currency.name === key" class="iconfont icon-duigou"></i>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import { CURRENCIES } from '@/constants/global'
import navigation from '@/components/Navigation'
export default {
  components: { navigation },
  data () {
    return {
      currencies: CURRENCIES
    }
  },
  computed: {
    ...mapState({
      currency: state => state.currency
    })
  },
  methods: {
    ...mapActions({
      setCurrency: 'setCurrency'
    }),
    changeFn (item) {
      this.setCurrency(item)
      this.$router.push({
        path: '/'
      })
    }
  }
}
</script>
<style scoped>
.list {
  background-color: #efefef;
  overflow: hidden;
}
.item {
  background: #fff;
  padding: 0 15px;
  height: 50px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.item span {
  font-size: 14px;
}
.item .iconfont {
  font-size: 18px;
  color: #ff976a;
}
</style>
